//
//  HS_importManager.m
//  悦享
//
//  Created by 韩双 on 16/3/19.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HS_importManager.h"

@interface HS_importManager ()

@property (nonatomic, strong) AVPlayer *player;

@end

static HS_importManager *instance = nil;

@implementation HS_importManager

+ (instancetype)shareManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[HS_importManager alloc] init];
    });
    return instance;
}


//播放音乐
- (AVPlayerLayer *)playingVideo:(NSString *)video_url
{
    self.player = [[AVPlayer alloc] init];
    AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init];
    
    video_url = [video_url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    // 创建播放项目对象
    AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:video_url]];
    // 创建承载播放器的layer
    [_player replaceCurrentItemWithPlayerItem:playerItem];
    
    // 设置视频填充模式
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

    // 创建承载播放器的layer
    playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
    
    return playerLayer;
}

- (void)play {
    
    [_player play];
}

- (void)pause {
    
    [_player pause];
}




@end
